
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include "log.h"
#include "fs.h"
#include "filelog.h"


int g_filelog = -1;
int g_inited = 0;


    int init_flog_new(const char* pFilename) {
    	close_flog();

    	char* pszLog = pFilename;
    	if (pszLog == NULL) {
    		pszLog = "/data/data/com.ijinshan.duba/files/rtr";
    	}

    	int rd = file_open(pszLog, O_WRONLY | O_CREAT | O_TRUNC);
    	g_filelog = rd;
    	if (g_filelog > -1) {
    		g_inited = 1;
    	}

    	return 0;
    }

    int flog_write(const char* pszContent) {

    	int size = 0;

    	if (pszContent == NULL) {
    		return 0;
    	}

    	size = strlen(pszContent);

    	LOGV("%s", pszContent);

    	if (g_inited == 1 && g_filelog != -1) {
    		file_write(g_filelog, pszContent, size, 1);
    	}

    	return 0;
    }


    int close_flog() {
    	if (g_inited != 0 && g_filelog > -1) {
    		file_close(g_filelog);

    		g_filelog = -1;
    		g_inited = 0;
    	}

    	return 0;
    }
